from rest_framework import serializers
from rest_framework.relations import StringRelatedField
from apps.goods.models import SPU, GoodsCategory
from rest_framework.views import APIView
from apps.goods.models import Brand


class SpuListModelSerializer(serializers.ModelSerializer):
    # 增加几个字段
    brand_id = serializers.IntegerField()
    brand = StringRelatedField()
    category1_id = serializers.IntegerField()
    category2_id = serializers.IntegerField()
    category3_id = serializers.IntegerField()
    class Meta:
        model = SPU
        fields = '__all__'


class BrandInfoModelSerializer(serializers.ModelSerializer):

    class Meta:
        model = Brand
        fields = ['id', 'name']


# 获取一级分类视图
class CategoryInfoModelSerializer(serializers.ModelSerializer):

    class Meta:
        model = GoodsCategory
        fields = ['id', 'name']
